<?php


/**
 * Класс Floor
 * класс, описывающий этаж торгового центра
 */
class Floor {
    public $id = 0;
    public $name = '';
    public $view_id = 0;        //
    public $picture = '';
    public $view_order = 0;
    public $dss;   // датчики

    private $data = array();           // данные







    public function __set($name, $value) {
        $this->data[$name] = $value;
    }

    public function __get($name) {
        return Arr::getValue($this->data, $name);
    }


    public function __construct($array=array()) {
        $this->setFromArray($array);
    }



    public function setFromArray($array=array()) {
        if (!is_array($array)) return;
        foreach ($array as $key => $val) {
            $this->$key = $val;
        }
    }


    public function readDss($reset = false) {
        if (!$reset && is_array($this->dss)) return $this->dss;

        $this->dss = array();
        if (!$this->id) return $this->dss;

        $q = "SELECT * FROM views_floors_sensors_list WHERE floor_id = $this->id";
        $res = DB::query($q);
        if (!$res || !DB::state()) return $out;

        while($row = mysqli_fetch_array($res, MYSQLI_ASSOC)){
            $s = new Flds($row);
            if ($s->id) $this->dss[$s->id] = $s;
        }

        return $this->dss;
    }

}
?>